/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * grafico.java
 *
 * Created on 09/09/2011, 08:26:32 PM
 */
package vista;

import controlador.principal;
import java.util.*;
import javax.swing.table.TableColumn;
import modelo.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author lidier
 */
public class grafico extends javax.swing.JFrame {
    static List l = null;

    /** Creates new form grafico */
    public grafico(List li, String nombre) {
        
        initComponents();
        String a = "Algoritmo -> "+nombre;
        if ("RoundRobin".equals(nombre))
            a = a + " (quantum = "+ principal.quantum+")";
         jLabel3.setText(a);
            
        grafico.l=new ArrayList<proceso>(li);
       /* if (l == null)
        {
            l = new ArrayList<proceso>();
        }
             
        proceso p;
        
        p = new proceso("p1",001,1,0);
        l.add(p);        
        p = new proceso("p2",001,4,3);
        l.add(p);
        int x=0, y=0;
        p = new proceso("p3",001,8,3);
        l.add(p);
        p = new proceso("p4",001,4,4);
        l.add(p);
        p = new proceso("p5",001,5,4);
        l.add(p);
       // p = new proceso("proc6",001,6,6);l.add(p);
        */
    }
    public void dibujar_procesos(){
        proceso p = null;
        DefaultTableModel model = (DefaultTableModel) T2.getModel();
            T2.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        int i=0;
        List laux =new ArrayList<proceso>(l);
        while (!l.isEmpty())
        {
            p = (proceso)l.get(0);
            l.remove(0);
            model.addColumn(p.nom);
            T2.setModel(model);
        } 
        int count=0;
        while (!laux.isEmpty())
        {
            p = (proceso)laux.get(0);
            laux.remove(0);
            T2.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            T2.getColumnModel().getColumn(i).setPreferredWidth(p.td*30);
            count += p.td;
            i+=1;
        } 
        int count2 = count;
        DefaultTableModel model2 = (DefaultTableModel) T1.getModel();
        for(int e=0; e<count; e++){
            model2.addColumn(e);
        }
            T1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        for(int e=0; e<count2; e++){
            T1.getColumnModel().getColumn(e).setPreferredWidth(30);
        }
    
    }
    

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        T2 = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        T1 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        T2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        T2.setName("T2"); // NOI18N
        jScrollPane2.setViewportView(T2);

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        T1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        T1.setName("T1"); // NOI18N
        jScrollPane3.setViewportView(T1);

        jLabel1.setText("Tiempo -> ");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText("Procesos ->");
        jLabel2.setName("jLabel2"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(grafico.class, this);
        jButton1.setAction(actionMap.get("Click")); // NOI18N
        jButton1.setText("Atras");
        jButton1.setName("Atras"); // NOI18N

        jLabel3.setText("jLabel3");
        jLabel3.setName("txt_nom"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 690, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(378, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(379, 379, 379))
            .addGroup(layout.createSequentialGroup()
                .addGap(364, 364, 364)
                .addComponent(jLabel3)
                .addContainerGap(396, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(8, 8, 8)
                .addComponent(jButton1)
                .addContainerGap())
        );

        jLabel3.getAccessibleContext().setAccessibleName("txt_nom");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    @org.jdesktop.application.Action
    public void Click() {
        principal.abrir_insertions(principal.seleccion, principal.quantum);
        this.dispose();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable T1;
    private javax.swing.JTable T2;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    // End of variables declaration//GEN-END:variables
}
